package triannon.client.sprites.renderer;

import java.awt.Color;
import java.awt.Graphics2D;

import org.newdawn.slick.util.pathfinding.Path;
import org.newdawn.slick.util.pathfinding.Path.Step;

import triannon.client.util.DebugUtil;
import triannon.client.util.TMath;

public class PathRenderer {

	public void paint(Graphics2D g, Step actStep, Path path) {
		if (path != null && path.getLength() > 0
				&& DebugUtil.getInstance().isRenderUnitPaths()) {
			g.setColor(Color.BLUE);
			g.drawLine(TMath.toWorldCoorninatesCenter(actStep.getX()), TMath
					.toWorldCoorninatesCenter(actStep.getY()), TMath
					.toWorldCoorninatesCenter(path.getStep(0).getX()), TMath
					.toWorldCoorninatesCenter(path.getStep(0).getY()));
			g.fillOval(TMath.toWorldCoorninatesCenter(actStep.getX()) - 4, TMath
					.toWorldCoorninatesCenter(actStep.getY()) - 3, 8, 6);

			for (int i = 0; i < path.getLength(); i++) {
				g.fillOval(TMath.toWorldCoorninatesCenter(path.getStep(i).getX()) - 3,
						TMath.toWorldCoorninatesCenter(path.getStep(i).getY()) - 2, 6, 4);
				if (i < path.getLength() - 1) {
					g.drawLine(TMath.toWorldCoorninatesCenter(path.getStep(i).getX()),
							TMath.toWorldCoorninatesCenter(path.getStep(i).getY()), TMath
									.toWorldCoorninatesCenter(path.getStep(i + 1).getX()), TMath
									.toWorldCoorninatesCenter(path.getStep(i + 1).getY()));
				}
			}
		}
	}

}
